/*************************************************************************
> File Name: app.cpp
> Author: hzy
> Created Time: 2023-08-17 09:56:14
> Description:模板类动态数组
************************************************************************/
#include "array.h"
#include "array.hpp"
#include "person.h"

// 测试当数组类型为int类型时
void test_01()
{
    MyArray<int> arr1;

    cout << "初始的数组容量和大小为：";
    cout << "capacity = " << arr1.getCapacity();
    cout << ", size = " << arr1.getSize() << endl;

    // 插入数据元素
    arr1.pushBack(55);
    arr1.pushBack(20);
    arr1.pushBack(22);
    arr1.pushBack(22);

    // 打印数组元素
    arr1.showArr();

    cout << "插入元素后的数组容量和大小为：";
    cout << "capacity = " << arr1.getCapacity();
    cout << ", size = " << arr1.getSize() << endl;

    cout << "删除后的元素为：" << endl;
    arr1.popBack();

    arr1.showArr();

    cout << "插入元素后的数组容量和大小为：";
    cout << "capacity = " << arr1.getCapacity();
    cout << ", size = " << arr1.getSize() << endl;
}

// 测试当数组类型为Person类时
void test_02()
{
    MyArray<Person> person;

    // 创建Person对象并初始化
    Person p1("狗大哥", 18);
    Person p2("猫小妹", 18);
    Person p3("猪猪", 30);
    Person p4("icebear", 99);
    Person p5("大胖猪", 88);
    // 添加Person对象到动态数组中
    person.pushBack(p1);
    person.pushBack(p2);
    person.pushBack(p3);
    person.pushBack(p4);
    person.pushBack(p5);

    person.showArr();

    // 用数组对象名+[]来指定位置并调用set方法修改数据
    person[1].setName("鸹貔");
    person[1].setAge(33);

    // 用Person对象名调用set方法修改数据，并将Person对象赋值给数组
    p1.setName("娃哈哈");
    p1.setAge(999);
    person[0] = p1;

    person.showArr();

    cout << "容量为：" << person.getCapacity();
    cout << ", 数组元素个数：" << person.getSize() << endl;
}

int main()
{
    test_01();
    cout << "=============================================" << endl;
    test_02();

    return 0;
}